<style lang="less">
@import '../../../styles/common.less';
</style>

<template>
    <Card style="height:800px">
        <Card>
            <div style="text-align:center;font-size: 34px;">
                新增预拨申请
            </div>
        </Card>
        <Card>
            <div style="margin-left: 44%;">
                <div style="margin-top:30px">
                    <div style="float:left;width:100px">划拨日期 ：</div>
                    <div>
                        <DatePicker v-model="transferCondition.transferDate" type="date" style="width: 150px"></DatePicker>
                    </div>
                </div>
                <div style="margin-top:30px">
                    <div style="float:left;width:100px">划拨金额：</div>
                    <div>
                        <Input v-model="transferCondition.transferAmount" style="width: 150px" />
                    </div>
                </div>
                <div style="margin-top:30px">
                    <div style="float:left;width:100px">项目名称：</div>
                    <div>
                        <Select v-model="transferCondition.projectCode" class="v-select-wrapper" style="width:150px" :label-in-value=true @on-change="projectChange">
                            <Option v-for="item in projectNameList" :value="item.key" :key="item.key">{{ item.label }}</Option>
                        </Select>
                    </div>
                </div>
                <div style="margin-top:30px">
                    <div style="float:left;width:100px">批次：</div>
                    <div>
                        <Input v-model="transferCondition.batchCode" @on-change="batchChange" style="width: 150px" />
                    </div>
                </div>
                <div style="margin-top:30px">
                    <div style="float:left;width:100px">文件名：</div>
                    <div>
                        <Input v-model="transferCondition.fileName" style="width: 150px" />
                    </div>
                </div>
                <div style="margin-top:30px;margin-left: 50px;">
                    <Button type="primary" @click="determineAdd">确定新增</Button>
                    <Button type="primary" @click="goBack" style="margin-left: 20px;">返回</Button>
                </div>
            </div>
        </Card>
    </Card>
</template>

<script>
export default {
  name: 'mutative-router',
  data () {
    return {
      transferCondition: {
        transferDate: '',
        transferAmount: '',
        projectCode: '',
        projectName: '',
        batchCode: '',
        fileName: '',
        capitalAasignAccount: ''
      },
      statusList: [
        {
          'key': '',
          'label': '请选择'
        },
        {
          'key': '1',
          'label': '已发送'
        },
        {
          'key': '0',
          'label': '待发送'
        },
        {
          'key': '2',
          'label': '已确认'
        }
      ],
      projectNameList: [
        {
          key: '',
          label: '请选择'
        },
        {
          key: 'YKD01',
          label: '云科谷个人消费贷款单一资金信托项目'
        }
      ]
    }
  },
  computed: {
    avatorImage () {
      return localStorage.avatorImgPath
    }
  },

  created () {
    // 初始化当前页面请求对象实例
    this.$ajax = this.$util.ajax()
  },

  methods: {
    determineAdd () {
      var vm = this
      if (vm.transferCondition.transferDate === '') {
        this.$Message.warning('请输入划拨日期')
        return
      }
      if (vm.transferCondition.transferAmount === '') {
        this.$Message.warning('请输入划拨金额')
        return
      }
      if (vm.transferCondition.projectCode === '') {
        this.$Message.warning('请输入项目名称')
        return
      }
      if (vm.transferCondition.batchCode === '') {
        this.$Message.warning('请输入批次')
        return
      }
      if (vm.transferCondition.fileName === '') {
        this.$Message.warning('请输入文件名')
        return
      }

      vm.transferCondition.capitalAasignAccount = this.convertCurrency(vm.transferCondition.transferAmount)
      this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/fund/bhLiquidation/service/addFundTransfer', vm.transferCondition).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        this.$Message.warning(message)
        if (code === 'success') {
          vm.goBack()
        }
      }).catch(er => {

      })
    },
    goBack () {
      this.$router.push({ name: 'bohai-fund-transfer' })// 类似post传参
    },
    projectChange (value) {
      var vm = this
      vm.transferCondition.projectName = value.label
    },
    batchChange () {
      var vm = this
      if (vm.transferCondition.projectCode === '') {
        this.$Message.warning('请输入项目名称')
        return
      }
      if (vm.transferCondition.transferDate === '') {
        this.$Message.warning('请输入划拨日期')
        return
      }
      if (vm.transferCondition.batchCode === '') {
        this.$Message.warning('请输入批次')
        return
      }
      var transferDate = vm.$util.loanModularFormatTime(vm.transferCondition.transferDate).replace(/\//g, '')
      vm.transferCondition.fileName = vm.transferCondition.projectCode + '_apply_' + transferDate + '_' + vm.formatInt(vm.transferCondition.batchCode)
    },

    formatInt (number) {
      if (number === '') return ''
      var mask = '000'
      var len = mask.length
      var returnVal = ''
      returnVal = mask + number
      returnVal = returnVal.substr(returnVal.length - len, len)
      return returnVal
    },
    convertCurrency (n) {
      var fraction = ['角', '分']
      var digit = [
        '零', '壹', '贰', '叁', '肆',
        '伍', '陆', '柒', '捌', '玖'
      ]
      var unit = [
        ['元', '万', '亿'],
        ['', '拾', '佰', '仟']
      ]
      var head = n < 0 ? '欠' : ''
      n = Math.abs(n)
      var s = ''
      for (var i = 0; i < fraction.length; i++) {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '')
      }
      s = s || '整'
      n = Math.floor(n)
      for (let i = 0; i < unit[0].length && n > 0; i++) {
        var p = ''
        for (var j = 0; j < unit[1].length && n > 0; j++) {
          p = digit[n % 10] + unit[1][j] + p
          n = Math.floor(n / 10)
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s
      }
      return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整')
    }

  }

}
</script>
<style>
</style>
